/**
 * Created by caosh on 2018/5/7 0007.
 */
var Random = Mock.Random;

// 子商城名称
Random.extend({
    tranSource: function(date) {
        var tranSources = ['42号公寓', '锐讯无限', '医美屋', '魔方公寓'];
        return this.pick(tranSources);
    }
});

// 子商城No
Random.extend({
    tranNo: function(date) {
        var tranNos = ['11111', '22222', '33333', '44444'];
        return this.pick(tranNos);
    }
});

var subMallMap = {
    '11111': '42号公寓'
    , '22222': '锐讯无限'
    , '33333': '医美屋'
    , '44444': '魔方公寓'
}

// 登录
Mock.mock('/login', 'post', function(options) {
    var params = getParams(options)
        , loginName = getParamValue(params, 'loginName')
        , password = getParamValue(params, 'password')
        , result = getResultTemplate();

    if (loginName!='admin' || password!='123456') {
        result.retCode = 1;
    } else {
        result.data = {
            'token': 'ask11dw3u0p4rwe32465436ghu85gd54r234jsdfk4k2p',
            'expiresIn':7200,
            'firstLogin' : Random.integer(0,1),
            'name': '魔力公寓',
            'url': 'pic/url'
        }
    }

    return result;
});

// 修改密码
Mock.mock('/editPwd', function (options) {
    var params = getParams(options)
        , loginName = getParamValue(params, 'loginName')
        , oldPwd = getParamValue(params, 'oldPwd')
        , newPwd = getParamValue(params, 'newPwd')
        , result = getResultTemplate();

    if (newPwd != '888888') {
        result.retCode = 1;
    }

    return result;
});

// 获取token
Mock.mock('/getAccessToken', 'post', function (options) {
    var result = getResultTemplate();
    result.data = {
        'accessToken': 'ask11dw3u0p4rwe32465436ghu85gd54r234jsdfk4k2p'
        , 'expiresIn': 7200 // 过期时间 （单位为秒）
    };
    return result;
});

// 退出
Mock.mock('/logout', 'post', function (options) {
    return getResultTemplate();
});

// 修改密码
Mock.mock('/editPwd', function (options) {
    return getResultTemplate();
});

// 获取银行列表
Mock.mock('/getBankList', function (options) {
    var result = getResultTemplate(),
        bankList = [];
    for(var i=0, len=Random.integer(0, 20); i<len; i++) {
        bankList.push({
            'sBankCode': Random.string('number', 12)
            , 'bankName': '中国建设银行股份有限公司总行'
            , 'shortName': '中国建设银行'
        });
    }

    result.data = bankList;

    return result;
});

// 个人用户绑定银行卡的短信发送
Mock.mock('/getMessageCode', function (options) {
    var result = getResultTemplate();

    return result;
});

// 个人用户绑定银行卡输入短信验证
Mock.mock('/authWithUnionPay', function (options) {
    var result = getResultTemplate();

    return result;
});

// 企业用户绑定银行卡打款
Mock.mock('/getTranAmount', function (options) {
    var result = getResultTemplate();

    return result;
});

// 企业用户绑定银行卡打款金额验证
Mock.mock('/authWithTranAmount', function (options) {
    var result = getResultTemplate();

    return result;
});

// 查询账户银行卡信息
Mock.mock('/getAcctInfo', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , acctId = getParamValue(params, 'acctId');

    result.data = {
        'acctType': 1,
        'acctOpenBranchName': '中国银行',
        'bankacctId': '***********'
    };

    return result;
});

// 获取菜单权限列表
Mock.mock('/getMenuList', function (options) {
    var result = getResultTemplate()
        , menuList = [];

    menuList.push({
        'name': '概况',
        'url': '../survey/index.html'
    });

    menuList.push({
        'name': '租务',
        'url': '../rental/index.html'
    });

    menuList.push({
        'name': '财务',
        'url': [{
            'name': '资金流水',
            'url': '../financial_affairs/index.html'
        }, {
            'name': '交易明细',
            'url': '../financial_affairs/transaction.html'
        }, {
            'name': '退款处理',
            'url': '../financial_affairs/refundment.html'
        }]
    });

    menuList.push({
        'name': '报表',
        'url': [{
            'name': '历史概况',
            'url': '../reports/index.html'
        }, {
            'name': '租务记录',
            'url': '../reports/rental_record.html'
        }]
    });

    menuList.push({
        'name': '分账',
        'url': [{
            'name': '分账方',
            'url': '../separate_accounts/index.html'
        }, {
            'name': '分账模板',
            'url': '../separate_accounts/template.html'
        }]
    });

    menuList.push({
        'name': '员工',
        'url': [{
            'name': '员工管理',
            'url': '../staff/index.html'
        }, {
            'name': '角色管理',
            'url': '../staff/role.html'
        }]
    });

    return result;
});

// 获取按钮权限列表
Mock.mock('/getBtnList', function (options) {
    var result = getResultTemplate()
        , btnList = [
            'addHouseSrc',
            'eidtHouseSrc',
            'addRoom',
            'editRoom',
            'deleteRoom',
            'signProtocol',
            'editProtocol',
            'getProtocolInfo',
            'refundRent',
            'getBills',
            'urgePayRent'
          ];

    result.data = btnList;
    return result;
});

// 添加房源
Mock.mock('/addHouseSrc', function (options) {
    var result = getResultTemplate();
    return result;
});

// 编辑房源
Mock.mock('/eidtHouseSrc', function (options) {
    var result = getResultTemplate();

    return result;
});

// 获取房源详情
Mock.mock('/getHouseSrcDetail', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , houseSrcId = getParamValue(params, 'houseSrcId');


    result.data = {
        'houseSrcId': houseSrcId,
        'houseName': '茉莉公寓',
        'temp': [
            {
                'code': 'fee_sf',
                'name': '水费',
                'tempId': 1
            },
            {
                'code': 'fee_df',
                'name': '电费',
                'tempId': 2
            },
            {
                'code': 'fee_rqf',
                'name': '燃气费',
                'tempId': 3
            },
            {
                'code': 'fee_wyf',
                'name': '物业费',
                'tempId': 4
            },
            {
                'code': 'fee_fwf',
                'name': '服务费',
                'tempId': 5
            },
            {
                'code': 'fee_bjf',
                'name': '保洁费',
                'tempId': 6
            },
            {
                'code': 'fee_wxf',
                'name': '维修费',
                'tempId': 7
            },
            {
                'code': 'fee_clf',
                'name': '材料费',
                'tempId': 8
            },
            {
                'code': 'fee_dsf',
                'name': '电视费',
                'tempId': 9
            },
            {
                'code': 'fee_kdf',
                'name': '宽带费',
                'tempId': 10
            },
            {
                'code': 'fee_wsf',
                'name': '卫生费',
                'tempId': 11
            },
            {
                'code': 'fee_qtf',
                'name': '其他费用',
                'tempId': 12
            }
        ]
    }

    return result;
});

//
Mock.mock('/getHouseSrcList', function (options) {
    var result = getResultTemplate()
        , houseSrcList = [];

    for(var i=0, len=Random.integer(0,6); i<len; i++) {
        houseSrcList.push({
            'houseSrcId': '20180'+Random.string('number', 3),
            'houseSrcName': '魔力公寓'+Random.string('number', 3),
            'totalHouse': Random.integer(8, 16)
        });
    }

    result.data = houseSrcList;
    return result;
});

//
Mock.mock('/getRoomList', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , houseSrcId = getParamValue(params, 'houseSrcId')
        , data = {}
        , roomList = [];

    data.houseSrcId = houseSrcId;
    data.houseSrcName = '魔力公寓';
    for (var i=0, len=Random.integer(0, 100); i<len; i++) {
        roomList.push({
            'roomId': Random.string('number', 8),
            'roomName': Random.string('number', 3),
            'status': Random.integer(0, 4),
            'date': Random.date('yyyy-MM-dd')
        });
    }

    data.roomList = roomList;
    result.data = data;
    return result;
});

//
Mock.mock('/queryRoomList', function (options) {
    var result = getResultTemplate();

    return result;
});

//
Mock.mock('/addRoom', function (options) {
    var result = getResultTemplate();

    return result;
});

//
Mock.mock('/editRoom', function (options) {
    var result = getResultTemplate();

    return result;
});

//
Mock.mock('/deleteRoom', function (options) {
    var result = getResultTemplate();

    return result;
});

//
Mock.mock('/uploadPic', function (options) {
    var result = getResultTemplate()
        , ids = [];

    for(var i=1, len=Random.integer(0, 40); i<len; i++) {
        ids.push(20180210+i);
    }

    result.data = ids;

    return result;
});

//
Mock.mock('/signProtocol', function (options) {
    var result = getResultTemplate();

    return result;
});

//
Mock.mock('/getCurrentProtocol', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , roomId = getParamValue(params, 'roomId');

    result.data = {
        "protocolId": 20180212,
        "houseSrcId": 320180213,
        "houseSrcName": "魔力公寓",
        "roomId": 20181214,
        "roomName": "201",
        "renterName": "胡歌",
        "phone": "18883288888",
        "idNumber": "500226199305218888",
        "idPic": [
            Random.image('117x80')
        ],
        "startDate": "2018-04-16",
        "endDate": "2019-04-15",
        "rental": 50000,
        "deposit": 20000,
        "payWay": 2,
        "rentWay": {
        "way": 0,
            "day": 2
        },
        "billPeriod": 0,
        "incidental ": [{
            "name": "水费",
            "chargeStandard": 0,
            "meterNumber": 0,
            "price": 1200,
            "meterDate": "2018-04-17"
        },{
            "name": "物业费",
            "chargeStandard": 0,
            "meterNumber": 0,
            "price": 1200,
            "meterDate": "2018-04-17"
        }]
    }


    return result;
});

//
Mock.mock('/getHistoryProtocol', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , roomId = getParamValue(params, 'roomId')
        , data = [];

    for(var i=0, len=Random.integer(0, 40); i<len; i++) {
        data.push({
            'renterName': Random.cname(),
            'type': Random.integer(0, 1),
            'date': Random.date('yyyy-MM-dd')
        });
    }

    result.data = data;
    return result;
});


Mock.mock('/editProtocolUnpaid', function () {
    return getResultTemplate();
});

Mock.mock('/editProtocolPaid', function () {
    return getResultTemplate();
});

Mock.mock('/refundRent', function () {
    return getResultTemplate();
});

Mock.mock('/getBills', function () {
    var result = getResultTemplate();
    result.data = {
        'renterId': 11111,
        'pending': {
            'billId': 123465,
            'startDate': '2018-04-16',
            'endDate': '2019-04-16',
            'status': '待支付',
            'money': 20000,
            'date': '2018-04-16'
        },
        'future': [{
            'billId': 123466,
            'startDate': '2018-04-16',
            'endDate': '2019-04-16',
            'money': 20000,
            'date': '2018-05-16'
        }],
        'history': [
            {
                'billId': 123467,
                'startDate': '2018-04-16',
                'endDate': '2019-04-16',
                'money': 20000,
                'date': '2018-03-16'
            },
            {
                'billId': 123468,
                'startDate': '2018-04-16',
                'endDate': '2019-04-16',
                'money': 20000,
                'date': '2018-02-16'
            }
        ]
    };

    return result;
});

Mock.mock('/getBillDetail', function () {
    var result = getResultTemplate()
        , detail = {
            'startDate': '2018-04-16',
            'endDate': '2019-04-16',
            'date': '2018-04-16',
            'info': [],
            'total': 2000000
        }
        , info = [];


    for (var i=0; i<10; i++) {
        info.push({
            'code': 'fee_sf',
            'money': 20000,
            'detail': {
                'lastNumber': 1000,
                'lastDate': '2018.03.01',
                'thisNumber': 1100,
                'thisDate': '2018.04.01',
                'price': 1100
            }
        });
    }

    detail.info = info;
    result.data = detail;

    return result;
});


Mock.mock('/urgePayRent', function () {
    return getResultTemplate();
});


Mock.mock('/getPayeeList', function () {
    var result = getResultTemplate()
        , payeeList = [];

    for (var i=0, len=Random.integer(0, 40); i<len; i++) {
        payeeList.push({
            'userId' : Random.string('number', 4),
            'name' : Random.string('number', 5),
            'acctType' : Random.integer(0, 3),
            'status' : Random.integer(0, 2),
            'bankName' : '中国银行',
            'bankCardNo' : '***********'+Random.string('number', 4),
            'amount' : Random.integer(0, 1000000)
        });
    }

    result.data = payeeList;
    return result;
});


Mock.mock('/addTemp', function () {
    var result = getResultTemplate();

    result.data = {'tempId': Random.integer(0, 100000)};
    return result;
});

Mock.mock('/editTemp', function () {
    return getResultTemplate();
});

Mock.mock('/getTemp', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , tempId = getParamValue(params, 'tempId')
        , payees = []
        , temp = {
            'tempId':tempId,
            'tempName': '模板1',
            'payees': [],
            'remark': '分账比例详细说明'
        };

    for(var i=0,len=Random.integer(0,20); i<len; i++) {
        payees.push(
            {
                'userId': Random.string('number', 3),
                'percent': parseInt(100/len)
            }
        );
    }

    temp.payees = payees;

    result.data = temp;
    return result;
});


Mock.mock('/getTempList', function () {
    var result = getResultTemplate()
        , tempList = [];

    for (var i=0, len=Random.integer(1, 20); i<len; i++) {
        var payees = []
            , temp = {
                'tempId':Random.string('number', 6),
                'tempName': '模板'+Random.string('number', 2),
                'payees': [],
                'remark': '分账比例详细说明',
                'items': '分账项目'
            };

        for(var j=0,len=Random.integer(0,20); j<len; j++) {
            payees.push(
                {
                    'userId': Random.cname(),
                    'percent': parseInt(100/len)
                }
            );
        }

        temp.payees = payees;

        tempList.push(temp);
    }

    result.data = tempList;

    return result;
});


Mock.mock('/getAccessList', function () {
    var result = getResultTemplate();
    result.data = [
        {
            "id": 1,
            "code": "1",
            "name": "概况",
            "resourceType": 1,
            "child": [
                {
                    "id": 2,
                    "code": "2",
                    "name": "查看概况页",
                    "resourceType": 1,
                    "child": []
                }
            ]
        },
        {
            "id": 3,
            "code": "3",
            "name": "租务",
            "resourceType": 1,
            "child": [
                {
                    "id": 4,
                    "code": "4",
                    "name": "房源管理",
                    "resourceType": 1,
                    child: [{
                        "id": 5,
                        "code": "5",
                        "name": "添加房源",
                        "resourceType": 2
                    }, {
                        "id": 6,
                        "code": "6",
                        "name": "编辑房源",
                        "resourceType": 2
                    }]
                }, {
                    "id": 7,
                    "code": "7",
                    "name": "房间管理",
                    "resourceType": 1,
                    child: [{
                        "id": 8,
                        "code": "8",
                        "name": "添加房间",
                        "resourceType": 2
                    }, {
                        "id": 9,
                        "code": "9",
                        "name": "编辑房间",
                        "resourceType": 2
                    }, {
                        "id": 10,
                        "code": "10",
                        "name": "删除房间",
                        "resourceType": 2
                    }]
                }, {
                    "id": 11,
                    "code": "11",
                    "name": "出租管理",
                    "resourceType": 1,
                    child: [{
                        "id": 12,
                        "code": "12",
                        "name": "添加租约",
                        "resourceType": 2
                    }, {
                        "id": 13,
                        "code": "13",
                        "name": "编辑租约",
                        "resourceType": 2
                    }, {
                        "id": 14,
                        "code": "14",
                        "name": "查看租约",
                        "resourceType": 2
                    }, {
                        "id": 15,
                        "code": "15",
                        "name": "办理退租",
                        "resourceType": 2
                    }]
                }, {
                    "id": 11,
                    "code": "11",
                    "name": "出租管理",
                    "resourceType": 1,
                    child: [{
                        "id": 16,
                        "code": "16",
                        "name": "查看账单",
                        "resourceType": 2
                    }, {
                        "id": 17,
                        "code": "17",
                        "name": "办理催租",
                        "resourceType": 2
                    }]
                }
            ]
        },
        {
            "id": 18,
            "code": "18",
            "name": "报表",
            "resourceType": 1,
            "child": [
                {
                    "id": 19,
                    "code": "19",
                    "name": "历史概况",
                    "resourceType": 1,
                    "child": []
                },
                {
                    "id": 20,
                    "code": "20",
                    "name": "租务记录",
                    "resourceType": 1,
                    "child": []
                }
            ]
        },
        {
            "id": 21,
            "code": "21",
            "name": "财务",
            "resourceType": 1,
            "child": [
                {
                    "id": 22,
                    "code": "22",
                    "name": "资金流水",
                    "resourceType": 1,
                    "child": []
                },
                {
                    "id": 23,
                    "code": "23",
                    "name": "交易明细",
                    "resourceType": 1,
                    "child": []
                },
                {
                    "id": 24,
                    "code": "24",
                    "name": "退款处理",
                    "resourceType": 1,
                    "child": []
                }
            ]
        },
        {
            "id": 25,
            "code": "25",
            "name": "角色",
            "resourceType": 1,
            "child": [
                {
                    "id": 26,
                    "code": "26",
                    "name": "员工管理",
                    "resourceType": 1,
                    "child": []
                },
                {
                    "id": 27,
                    "code": "27",
                    "name": "角色管理",
                    "resourceType": 1,
                    "child": []
                }
            ]
        },
        {
            "id": 28,
            "code": "28",
            "name": "其他",
            "resourceType": 1,
            "child": [
                {
                    "id": 29,
                    "code": "29",
                    "name": "微信概况页",
                    "resourceType": 1,
                    "child": []
                },
                {
                    "id": 30,
                    "code": "30",
                    "name": "微信抄表",
                    "resourceType": 1,
                    "child": []
                }
            ]
        }
    ];

    return result;
});

Mock.mock('/addRole', function () {
    var result = getResultTemplate();
    result.data = {'roleId': Random.string('number', 4)};

    return result;
});

Mock.mock('/editRole', function () {
    var result = getResultTemplate();


    return result;
});

Mock.mock('/getRoleList', function () {
    var result = getResultTemplate()
        , roleList = [];

    for (var i=0, len=Random.integer(0, 10); i<len; i++) {
        roleList.push({
            'roleId': parseInt(Random.string('number', 4)),
            'roleName': 'xxxx'+i,
            'roleDesc': '角色描述'+i,
            'createTime': Random.date('yyyy-MM-dd HH:mm:ss')
        });
    }

    result.data = roleList;

    return result;
});

Mock.mock('/addEmpl', function () {
    var result = getResultTemplate();


    return result;
});

Mock.mock('/editEmpl', function () {
    var result = getResultTemplate();


    return result;
});

Mock.mock('/getEmplList', function () {
    var result = getResultTemplate()
        , empllist = [];

    for (var i=0, len=Random.integer(0, 100); i<len; i++) {
        empllist.push({
            'emplName': Random.cname(),
            'loginName': Random.email('migy'),
            'createTime': Random.date('yyyy-MM-dd HH:mm:ss'),
            'roleId': parseInt(Random.string('number', 4)),
            'roleName': 'xxxx'
        });
    }

    result.data = empllist;

    return result;
});

Mock.mock('/getAptPending', function () {
    var result = getResultTemplate();
    result.data = {
        'nearRent': 15,
        'overdue': 15,
        'nearExpire': 15
    };

    return result;
});

Mock.mock('/withdrawCash', function (options) {
    return getResultTemplate();
});

// 查询账户资金概况
/*Mock.mock('/getAcctFundInfo', 'post', function (options) {
    var result = getResultTemplate();
    result.data = {
        'withdrawCash': 20000
        , 'awaitSettle': 10000
        , 'availBal': 50000
        , 'cashAmt': 40000
        , 'fundSumAcctNo': 20000
    };
    return result;
});*/


// 查询账户资金流水详情
Mock.mock('/getAcctFundSeq', 'post', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , paginator = getPaginatorTemplate(params)
        , acctFundList= [];


    Random.extend({
        remark: function(date) {
            var remarks = ['-', '平台', '用户：xxx'];
            return this.pick(remarks);
        }
    });


    Random.extend({
        tranType: function(date) {
            var tranTypes = ['UBK服务费', '提现', '交易服务费', '代扣鉴权费', '代扣支付通道费'];
            return this.pick(tranTypes);
        }
    });

    for(var i=0, len=getLength(paginator); i<len; i++) {
        acctFundList.push({
            'billNo': Random.string( 'number', 16 ),
            'paySeqNo': Random.string( 'number', 9 ),
            'tranSeqNo': Random.string( 'number', 11 ),
            'tranType': Random.tranType(),
            'tranSource': Random.tranSource(),
            'billCreateTime': Random.date('yyyy-MM-dd HH:mm:ss'),
            'tranAmt': Random.float(-100000, 100000, 2, 2),
            'remark': Random.remark()
        });
    }

    result.data = {'paginator': paginator, 'acctFundList': acctFundList};

    return result;
});

// 子商城交易总览
Mock.mock('/getTranOverview', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , paginator = getPaginatorTemplate(params)
        , tranOverview= [];

    for(var i=0; i<getLength(paginator); i++) {
        var sevenDayTranSeq = Random.integer( 0, 100000 )
            , subMallNo = Random.tranNo();
        tranOverview.push({
            'subMallNo': subMallNo,
            'subMallName': subMallMap[subMallNo],
            'sevenDayTranSeq': sevenDayTranSeq,
            'totalTranSeq': Random.integer( sevenDayTranSeq, 110000 )
        });
    }

    result.data = {'paginator': paginator, 'tranOverview': tranOverview};

    return result;
});

// 获取子商城列表
Mock.mock('/getSubMallList', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , paginator = getPaginatorTemplate(params)
        , subMallList= [];

    for(var i=0; i<getLength(paginator); i++) {
        var subMallNo = Random.tranNo();
        subMallList.push({
            'subMallNo': subMallNo
            , 'subMallName': subMallMap[subMallNo]
            , 'createTime': Random.date('yyyy-MM-dd HH:mm:ss')
        });
    }

    result.data = {'paginator': paginator, 'subMallList': subMallList};

    return result;
});

// 获取子商城详情
Mock.mock('/getSubMallDetail', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , subMallNo = getParamValue(params, 'subMallNo');

    result.data = {
        'subMallNo': subMallNo,
        'subMallName': subMallMap[subMallNo],
        'createTime': Random.date('yyyy-MM-dd HH:mm:ss'),
        'loginName': Random.email('126.com'),
        'password': Random.string('number', 6),
        'subAcctNo': Random.string('number', 15),
        'idCardType': 'xxxxxxxxxxxxxx',
        'idCardNo': 'xxxxxxxxxxxxxx',
        'bankcardNo': 'xxxxxxxxxxxxxx',
        'bankName': 'xxxxxxxxxxxxxx'
    };

    return result;
});

// 创建子商城
Mock.mock('/createSubMall', function (options) {
    return getResultTemplate();
});

// 编辑子商城
Mock.mock('/editSubMall', function (options) {
    return getResultTemplate();
});

// 获取分账模版
Mock.mock('/getModelList', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , paginator = getPaginatorTemplate(params)
        , modelList = [];

    for (var i=0, len=getLength(paginator); i<len; i++) {
        modelList.push({
            'modelName': Random.tranSource(),
            'remark': '42号商城20%，谭新年80%'
        });
    }

    result.data = {'paginator': paginator, 'modelList': modelList};

    return result;
});

// 获取供应商信息
Mock.mock('/getSupplierList', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , paginator = getPaginatorTemplate(params)
        , supplierList = [];

    for (var i=0, len=getLength(paginator); i<len; i++) {
        supplierList.push({
            'payeeName': Random.cname(),
            'bankBindStatus': '已绑定',
            'bankName': '中国银行',
            'bankAcctNo': '***********'+Random.string('number', 4),
            'subAcctNo': 'xxxxx',
            'totalAmt': 2000000
        });
    }

    result.data = {'paginator': paginator, 'supplierList': supplierList};
    return result;
});


// 获取商品信息
Mock.mock('/getGoodsList', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , paginator = getPaginatorTemplate(params)
        , goodsList = [];

    for (var i=0, len=getLength(paginator); i<len; i++) {
        goodsList.push({
            'goodsNo': 'xxxxxxxxxxxxxx',
            'goodsName': 'xxxxxxxxxxxxxx',
            'remark': '房租1：42号商城20%，谭新年80%',
            'specification': Random.string('number', 10)
        });
    }

    result.data = {'paginator': paginator, 'goodsList': goodsList};
    return result;
});


// 获取用户信息
Mock.mock('/getUserInfo', function (options) {
    var result = getResultTemplate(),
        params = getParams(options),
        userType = getParamValue(params, 'userType'),
        userValue = getParamValue(params, 'userValue'),
        uid = '123465',
        userName = 'beyond',
        subAcctNo = 'test',
        phone = '18888888888';

    if (userType == 0) {
        uid = userValue;
    } else if (userType == 1) {
        userName = userValue;
    } else if (userType == 2) {
        subAcctNo = userValue;
    } else if (userType == 3) {
        phone = userValue;
    }

    result.data = {
        'uid': uid,
        'userName': userName,
        'subAcctNo': subAcctNo,
        'phone': phone
    };

    return result;
});

// 获取用户交易记录
Mock.mock('/getUserTranList', function (options) {
    var result = getResultTemplate()
        , params = getParams(options)
        , paginator = getPaginatorTemplate(params)
        , tranList = [];

    for (var i=0, len=getLength(paginator); i<len; i++) {
        tranList.push({
            'billNo': 'xxxxxxxxxxxxxx',
            'paySeqNo': 'xxxxxxxxxxxxxx',
            'tranSeqNo': 'xxxxxxxxxxxxxx',
            'goodsName': Random.string(),
            'tranType': '交易服务费',
            'tranTime': Random.date('yyyy-MM-dd HH:mm:ss'),
            'tranAmt': 20000
        });
    }

    result.data = {'paginator': paginator, 'tranList': tranList};
    return result;
});


// 获取收费设置
Mock.mock('/getPayConf', function (options) {
    var result = getResultTemplate(),
       params = getParams(options),
       subMallNo = getParamValue(params, 'subMallNo');

    result.data = {
       'subMallNo': subMallNo,
       'UBKDivide': 1.5,
       'personal': {
           'takeCashComm': 1.5,
           'lowest': 100,
           'highest': 500
       },
       'company': {
           'takeCashComm': 0.15,
           'lowest': 100,
           'highest': 500
       },
       'suppTakeCashComm': 1,
       'userTakeCashComm': 1,
       'weChat': 1.5,
       'aliPay': 1.5,
       'barcodePay': 1.5,
       'gatewayPay': 1.5,
       'userPayChannFee': 1,
       'userIdVer': 2,
       'bandAcctAuth': 5,
       'interfaceCall': 10,
       'subMallSubAcct': 20000,
       'supplierSubAcct': 20000
    };
    return result;
});

// 收费设置
Mock.mock('/setPayConf', function (options) {
    return getResultTemplate();
});


// 获取交易记录列表
Mock.mock('/getTranList', function (options) {
    var result = getResultTemplate(),
        params = getParams(options),
        paginator = getPaginatorTemplate(params),
        billList = [],
        goodsList = [],
        tranList = [];

    for (var i=0, len=paginator.pageSize; i<len; i++) {
        tranList.push({
            'tranSeqNo': 'xxxxxxxx',
            'payee': 'UBK',
            'payeeAmt': Random.integer(500, 100000)
        });
    }

    for (var i=0, len=tranList.length/2; i<len; i++) {
        var tArr = tranList.slice(i*2, i*2+2);
        goodsList.push({
            'goodsType': '房租',
            'payAmt': 20000,
            'tranList': tArr
        });
    }

    for(var i=0, len=goodsList.length/2; i<len; i++) {
        var gArr = goodsList.slice(i*2, i*2+2);
        billList.push({
            'billNo': 'xxxxxxxxxxxxxx',
            'paySeqNo': 'xxxxxxxxxxxxxx',
            'billCreateTime': Random.date('yyyy-MM-dd HH:mm:ss'),
            'billStatus': '交易成功',
            'payerNo': 121212121,
            'payer': 'xxx',
            'goodsList':gArr
        });
    }

    result.data = {'paginator': paginator, 'billList': billList};
    return result;
});


Mock.mock('/getTranDetail', function (options) {
    var result = getResultTemplate(),
        tranDetail = {},
        goodsList = [],
        tranList = [];

    for (var i=0; i<20; i++) {
        tranList.push({
            'tranSeqNo': 'xxxxxxxx',
            'payee': 'UBK',
            'payeeAmt': Random.integer(500, 100000)
        });
    }

    for (var i=0, len=tranList.length/2; i<len; i++) {
        var tArr = tranList.slice(i*2, i*2+2);
        goodsList.push({
            'goodsType': '房租',
            'payAmt': 20000,
            'tranList': tArr
        });
    }

    tranDetail = {
        'billNo': 'xxxxxxxxxxxxxx',
        'paySeqNo': 'xxxxxxxxxxxxxx',
        'billCreateTime': Random.date('yyyy-MM-dd HH:mm:ss'),
        'billStatus': '交易成功',
        'payerNo': 121212121,
        'payer': 'xxx',
        'billList':goodsList
    };

    result.data = tranDetail;
    return result;
});

//获取历史概况
Mock.mock('/getApartmentDaily', function (options) {
    var result = getResultTemplate(),
        params = getParams(options),
        paginator = getPaginatorTemplate(params),
        dailyList = [],
        empty, total;

    for (var i=0, len=getLength(paginator); i<len; i++) {
        total = parseInt(Random.string('number', 3));
        empty = parseInt(Random.string('number', 2));
        dailyList.push({
            'date': Random.date('yyyy-MM-dd'),
            'rentNewRoom': parseInt(Random.string('number', 2)),
            'rentBackRoom': parseInt(Random.string('number', 1)),
            'totalRoom': total,
            'renting': parseInt(Random.string('number', 3)),
            'emptyRoom': empty,
            'emptyPercent': (empty/total).toFixed(2),
            'rent': parseInt(Random.string('number', 6)),
            'deposit': parseInt(Random.string('number', 6)),
            'otherFees': parseInt(Random.string('number', 6)),
            'refund': parseInt(Random.string('number', 5))
        });
    }

    result.data = {'paginator': paginator, 'dailyList': dailyList};

    return result;
});

//获取租务记录
Mock.mock('/getOperateRecord', function (options) {
    var result = getResultTemplate(),
        params = getParams(options),
        paginator = getPaginatorTemplate(params),
        recordList = [];

    for (var i=0, len=getLength(paginator); i<len; i++) {
        recordList.push({
            'id': parseInt(Random.string('number', 3)),
            'protocolId':parseInt(Random.string('number', 6)),
            'operateType':Random.integer(0, 2),
            'agentId': parseInt(Random.string('number', 6)),
            'agentName': Random.cname(),
            'time': Random.date('yyyy-MM-dd HH:mm:ss'),
            'roomName':'魔力公寓'+parseInt(Random.string('number', 1))+'-'+parseInt(Random.string('number', 3)),
            'name': Random.cname(),
        });
    }

    result.data = {'paginator': paginator, 'recordList': recordList};

    return result;
});

//获取租务详情
Mock.mock('/getRecordInfo', function (options) {
    var result = getResultTemplate(),
        params = getParams(options),
        recordInfo = {},
        incidental = []
        name = ['水费','物业费','网费','电费','煤气费'],
        standard = [0,0,0,1,1];

    for (var i=0, len=Random.integer(0, 4); i<len; i++) {
        incidental.push({
            'name': name[i],
            'chargeStandard':standard[i],
            'meterNumber':parseInt(Random.string('number', 4)),
            'price':parseInt(Random.string('number', 2)),
            'meterDate':Random.date('yyyy-MM-dd')
        })
    }

    recordInfo = {
        'recordId': params.recordId,
        'operateType': 0,
        'roomId': parseInt(Random.string('number', 8)),
        'renterName': Random.cname(),
        'phone': 'xxxx',
        'idNumber': parseInt(Random.string('number', 18)),
        'idPic1':['pic1','pic2','pic3'],
        'startDate': Random.date('yyyy-MM-dd'),
        'endDate': Random.date('yyyy-MM-dd'),
        'rental': parseInt(Random.string('number', 5)),
        'deposit': parseInt(Random.string('number', 5)),
        'payWay': parseInt(Random.string('number', 1)),
        'rentWay': {
            'way': Random.integer(0, 1),
            'day': parseInt(Random.string('number', 1))
        },
        'billPeriod': Random.integer(0, 1),
        'incidental': incidental
    };

    result.data = recordInfo;

    return result;
});

//获取账户资金
Mock.mock('/getAcctFundInfo', function (options) {
    var result = getResultTemplate();

    result.data = {
        'balance' : parseInt(Random.string('number', 6)),
        'cashAmt' : parseInt(Random.string('number', 5)),
        'aCashAmt' : parseInt(Random.string('number', 7)),
        'settlement' : parseInt(Random.string('number', 5))
    };

    return result;
});

//查询资金流水
Mock.mock('/getFundFlow', function (options) {
    var result = getResultTemplate(),
        params = getParams(options),
        paginator = getPaginatorTemplate(params),
        billList = [];

    for (var i=0, len=getLength(paginator); i<len; i++) {
        billList.push({
            'billNo': parseInt(Random.string('number', 11)),
            'payNo': parseInt(Random.string('number', 9)),
            'tranFlowNo': parseInt(Random.string('number', 11)),
            'tranType': '平台手续费',
            'tranTime': Random.date('yyyy-MM-dd'),
            'tranAmount': parseInt(Random.string('number', 4)),
            'tranSource':Random.cname(),
            'status': Random.integer(0, 4)
        })
    }

    result.data = {'paginator': paginator, 'billList': billList};

    return result;
});

//查询交易明细列表
Mock.mock('/getOrderDetailList', function (options) {
    var result = getResultTemplate(),
        params = getParams(options),
        paginator = getPaginatorTemplate(params),
        billList = [];

    for (var i=0, len=Random.integer(0, 20); i<len; i++) {
        billList.push({
            'billNo': parseInt(Random.string('number', 11)),
            'payNo': parseInt(Random.string('number', 9)),
            'payTime': Random.date('yyyy-MM-dd HH:mm:ss'),
            'buyerId': parseInt(Random.string('number', 9)),
            'buyerName': Random.cname(),
            'billStatus': Random.integer(0, 4),
            'house': '魔力公寓'+parseInt(Random.string('number', 1))+'-'+parseInt(Random.string('number', 3)),
            'goodsList': [{
                'goodsNo': parseInt(Random.string('number', 11)),
                'feeType': Random.integer(0, 4),
                'payAmt': parseInt(Random.string('number', 5)),
                'tranList': [{
                    'tranFlowNo': parseInt(Random.string('number', 11)),
                    'payeeName': Random.cname(),
                    'payeeId': parseInt(Random.string('number', 9)),
                    'payeeAmt': parseInt(Random.string('number', 5)),
                    'status': Random.integer(0, 4),
                    'tranTime': Random.date('yyyy-MM-dd HH:mm:ss')
                },{
                    'tranFlowNo': parseInt(Random.string('number', 11)),
                    'payeeName': Random.cname(),
                    'payeeId': parseInt(Random.string('number', 9)),
                    'payeeAmt': parseInt(Random.string('number', 5)),
                    'status': Random.integer(0, 4),
                    'tranTime': Random.date('yyyy-MM-dd HH:mm:ss')
                }]
            },{
                'goodsNo': parseInt(Random.string('number', 11)),
                'feeType': Random.integer(0, 4),
                'payAmt': parseInt(Random.string('number', 5)),
                'tranList': [{
                    'tranFlowNo': parseInt(Random.string('number', 11)),
                    'payeeName': Random.cname(),
                    'payeeId': parseInt(Random.string('number', 9)),
                    'payeeAmt': parseInt(Random.string('number', 5)),
                    'status': Random.integer(0, 4),
                    'tranTime': Random.date('yyyy-MM-dd HH:mm:ss')
                },{
                    'tranFlowNo': parseInt(Random.string('number', 11)),
                    'payeeName': Random.cname(),
                    'payeeId': parseInt(Random.string('number', 9)),
                    'payeeAmt': parseInt(Random.string('number', 5)),
                    'status': Random.integer(0, 4),
                    'tranTime': Random.date('yyyy-MM-dd HH:mm:ss')
                }]
            }]
        });
    }

    result.data = {'paginator': paginator, 'billList': billList};

    return result;
});

//查询交易明细列表
Mock.mock('/getOrderDetail', function (options) {
    var result = getResultTemplate(),
        params = getParams(options);

    result.data =  {
            'billNo': parseInt(Random.string('number', 11)),
            'payNo': parseInt(Random.string('number', 9)),
            'payTime': Random.date('yyyy-MM-dd HH:mm:ss'),
            'buyerId': parseInt(Random.string('number', 9)),
            'buyerName': Random.cname(),
            'billStatus': Random.integer(0, 4),
            'house': '魔力公寓'+parseInt(Random.string('number', 1))+'-'+parseInt(Random.string('number', 3)),
            'goodsList': [{
                'goodsNo': parseInt(Random.string('number', 11)),
                'feeType': Random.integer(0, 4),
                'payAmt': parseInt(Random.string('number', 5)),
                'tranList': [{
                    'tranFlowNo': parseInt(Random.string('number', 11)),
                    'payeeName': Random.cname(),
                    'payeeId': parseInt(Random.string('number', 9)),
                    'payeeAmt': parseInt(Random.string('number', 5)),
                    'status': Random.integer(0, 4),
                    'tranTime': Random.date('yyyy-MM-dd HH:mm:ss')
                },{
                    'tranFlowNo': parseInt(Random.string('number', 11)),
                    'payeeName': Random.cname(),
                    'payeeId': parseInt(Random.string('number', 9)),
                    'payeeAmt': parseInt(Random.string('number', 5)),
                    'status': Random.integer(0, 4),
                    'tranTime': Random.date('yyyy-MM-dd HH:mm:ss')
                }]
            },{
                'goodsNo': parseInt(Random.string('number', 11)),
                'feeType': Random.integer(0, 4),
                'payAmt': parseInt(Random.string('number', 5)),
                'tranList': [{
                    'tranFlowNo': parseInt(Random.string('number', 11)),
                    'payeeName': Random.cname(),
                    'payeeId': parseInt(Random.string('number', 9)),
                    'payeeAmt': parseInt(Random.string('number', 5)),
                    'status': Random.integer(0, 4),
                    'tranTime': Random.date('yyyy-MM-dd HH:mm:ss')
                },{
                    'tranFlowNo': parseInt(Random.string('number', 11)),
                    'payeeName': Random.cname(),
                    'payeeId': parseInt(Random.string('number', 9)),
                    'payeeAmt': parseInt(Random.string('number', 5)),
                    'status': Random.integer(0, 4),
                    'tranTime': Random.date('yyyy-MM-dd HH:mm:ss')
                },{
                    'tranFlowNo': parseInt(Random.string('number', 11)),
                    'payeeName': Random.cname(),
                    'payeeId': parseInt(Random.string('number', 9)),
                    'payeeAmt': parseInt(Random.string('number', 5)),
                    'status': Random.integer(0, 4),
                    'tranTime': Random.date('yyyy-MM-dd HH:mm:ss')
                }]
            }]
        };

    return result;
});



//查询退租退款列表
Mock.mock('/getRefundList', function (options) {
    var result = getResultTemplate(),
        params = getParams(options),
        paginator = getPaginatorTemplate(params),
        refundList = [];

    for (var i=0, len=Random.integer(0, 100); i<len; i++) {
        refundList.push({
            'refundId': parseInt(Random.string('number', 6)),
            'agentName': Random.cname(),
            'reqTime': Random.date('yyyy-MM-dd HH:mm:ss'),
            'buyerId': parseInt(Random.string('number', 9)),
            'buyerName': Random.cname(),
            'roomName': '魔力公寓'+parseInt(Random.string('number', 1))+'-'+parseInt(Random.string('number', 3)),
            'amount': parseInt(Random.string('number', 6)),
            'refundTime': Random.date('yyyy-MM-dd HH:mm:ss'),
            'refundName': Random.cname(),
            'status':Random.integer(0, 1)
        })
    }

    result.data = {'paginator': paginator, 'refundList': refundList};

    return result;
});

//确认退租退款
Mock.mock('/confirmRefundOffLine', function (options) {
    var result = getResultTemplate(),
        params = getParams(options);

    return result;
});

//确认原路退款
Mock.mock('/confirmRefundOnLine', function (options) {
    var result = getResultTemplate(),
        params = getParams(options);

    return result;
});


function getPaginatorTemplate(params) {
    var pageNo = getParamValue(params, 'pageNo')
        , pageSize = getParamValue(params, 'pageSize')
        , totalNum = Random.integer(0, 100)
        , paginator = {'pageNo': pageNo, 'pageSize': pageSize, 'pageNum': 5, 'totalNum': totalNum, 'totalPage': Math.ceil(totalNum/pageSize)};

    return paginator;
}

function getLength(paginator) {
    return Math.min(paginator.pageSize, paginator.totalNum);
}

// 获取返回值模板
function getResultTemplate() {
    return {retCode: 0, errMsg: '', data: null};
}

// 获取请求参数数组
function getParams(options) {
    var body = options.body,
        params = JSON.parse(body);
    return params.data;
}

// 获取对应参数的值
function getParamValue(params, k) {
    var v = null;
    if (params != null) {
        v = params[k];
    }
    return v;
}